package com.zheng.api.server.controller;

import com.zheng.api.server.service.base.um.Base4UmbrellaService;
import com.zheng.common.base.BaseController;
import com.zheng.common.constant.Constant;
import com.zheng.upms.dao.model.UpmsAgent;
import com.zheng.upms.rpc.api.UpmsAgentService;
import io.swagger.annotations.Api;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 后台controller
 * Created by shuzheng on 2017/2/19.
 * https://www.bjs-tech.cn/api/mqrcode/prod/
 * https://www.bjs-tech.cn/api/mqrcode/dev/
 * https://www.bjs-tech.cn/api/mqrcode/test/
 */

@Controller
@Api(value = "mqrcode", description = "mqrcode")
@RequestMapping(value = "/mqrcode")
public class MQRCodeController extends BaseController {

	private static final Logger LOGGER = LoggerFactory.getLogger(MQRCodeController.class);
    @Autowired
    UpmsAgentService upmsAgentService;
    @Autowired
    Base4UmbrellaService base4UmbrellaService;

	@RequestMapping(value = "/{agentCode}/{code}")
	public String prod(@PathVariable("agentCode") String agentCode,@PathVariable("code") String code, ModelMap modelMap) {
		String machineCode = "";
		if(StringUtils.isNotBlank(code)){
			machineCode = machineCode + code.substring(code.lastIndexOf("/")+1);
		}
		Integer agentId = Constant.CONST_SUPER_AGENTID;
		try{
            agentId = base4UmbrellaService.baseSelectUmbrellaHardwareMachineNoCache(code).getAgentId();
        }catch (Exception e){
            agentId = Constant.CONST_SUPER_AGENTID;
        }
        UpmsAgent upmsAgent = upmsAgentService.selectByPrimaryKey(agentId);
		modelMap.put("agentName",upmsAgent.getName());
		modelMap.put("machineCode", machineCode);
		return "/front/mqrcode/index.jsp";
	}
}